package com.itheima.publisher;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class TopicTest {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void testTopicExchange() {
        // 测试不同的routing key，观察消息路由到不同的队列
        
        // 发送到 topic.queue1 (匹配 order.*)
        rabbitTemplate.convertAndSend("hmall.topic", "order.create", "订单创建消息");
        rabbitTemplate.convertAndSend("hmall.topic", "order.update", "订单更新消息");
        rabbitTemplate.convertAndSend("hmall.topic", "order.delete", "订单删除消息");
        
        // 发送到 topic.queue2 (匹配 *.create)
        rabbitTemplate.convertAndSend("hmall.topic", "user.create", "用户创建消息");
        rabbitTemplate.convertAndSend("hmall.topic", "product.create", "商品创建消息");
        rabbitTemplate.convertAndSend("hmall.topic", "order.create", "订单创建消息（也会发送到queue2）");
        
        // 发送到 topic.queue3 (匹配 order.#)
        rabbitTemplate.convertAndSend("hmall.topic", "order.create", "订单创建消息（也会发送到queue3）");
        rabbitTemplate.convertAndSend("hmall.topic", "order.update.status", "订单状态更新消息");
        rabbitTemplate.convertAndSend("hmall.topic", "order.payment.success", "订单支付成功消息");
        
        System.out.println("Topic消息发送完成！");
    }
} 